﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using d1Common.WebController;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using d1Common;
using d1Common.Interface;
using Newtonsoft.Json.Linq;
using d1Project.Modules.Common.do4A.Models;
using d1Project.Modules.Common.do4A.Domain;

namespace d1Project.Modules.Common.do4A.Controllers.a1
{
    [Route("do4A/a1/MyPemissions")]
    public class MyPemissionsController : Authorize1Controller
    {
        protected override DbContext dbContext
        {
            get
            {
                return this.db;
            }
        }
        private do4ADbContext db = new do4ADbContext();
        public IHttpActionResult Get()
        {
            List<MyPermissionsResGetVm> list = new List<MyPermissionsResGetVm>();
            if (string.IsNullOrEmpty(this.RoleId)) return Ok(list);

            IDictionary<string, IRolePermission> PermissionList = PermissionMgr.Instance.GetRolePermissionsLocal(this.RoleId);

            foreach (var item in PermissionList)
            {
                MyPermissionsResGetVm mypermissions = new MyPermissionsResGetVm();
                mypermissions.PermissionId = item.Value.PermissionId;
                mypermissions.Operations = item.Value.Operations;
                list.Add(mypermissions);
            }
            return Ok(list);
        }

    }

    public class MyPermissionsResGetVm
    {
        /// <summary>
        /// 权限Id
        /// </summary>
        public string PermissionId { get; set; }

        /// <summary>
        /// 操作权限 
        /// </summary>
        public int Operations { get; set; }

    }
}